package com.yanqu.road.server.logic.activity.condition;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.task.args.union.UnionActivityBaseArgs;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

public abstract class BaseUnionActivityCondition extends BaseActivityCondition {

	public BaseUnionActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	public final void setUnionActivityDefaultValue(UnionActivityBaseArgs args) {
		if(!StringUtils.isNullOrEmpty(args.getUnionUid())) {
			UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(getConditionId());
			setUnionActivityData(args, userActivityConditionData);
		}
	}

	public final void setUnionActivityValue(BigInteger value,UnionActivityBaseArgs args) {
		UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(getConditionId());
		setUnionActivityData(args, userActivityConditionData);
	}

	private void setUnionActivityData(UnionActivityBaseArgs args, UserActivityConditionData userActivityConditionData) {
		UnionActivityMgr.saveUnionActivityValue(activityInfo.getActivityId(),userActivityConditionData, args);
		player.getModule(ActivityModule.class).onActivityDataChanged(baseActivityData);
	}

}
